-
Notifications
You must be signed in to change notification settings - Fork 216
add esp32 support #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add esp32 support #174
Conversation
ESP32-C3 compiles as well now but not tested on hardware |
Hi @dominsch, by when can we expect this branch merged into the master branch? |
I'm not involved in this project and it is entirely up to the maintainers if they want to add esp32 support. Maybe if enough people express interest they will consider merging. |
@dominsch I tried code from your fork but it gives compile error. May be it is my lack of understanding on how to run it. The error is because of the following include statements:
in the |
@haptork i fixed this issue by creating a folder called |
Immediately after posting that, i noticed that
were also not included. Time to google some more. |
FreeRTOS headers should be included with arduino-esp32, just like the bluetooth files. Do the regular bluetooth examples compile for you? |
Just checked it on a different computer with clean arduino install and it compiled. Make sure you have arduino for esp32 version 2.0.0 or later. This is the link you want to be using in your board manager: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json. They used to use https://dl.espressif.com/dl/package_esp32_index.json but that has become stale and doesn't go beyond 1.0.6 |
@dominsch Thank you. Yes it works well with version 2.0.2. I am using platform.io which is still stuck in ver 1.0.6 and working with version 2 needs some hack. |
It shouldn't be hard to get it to work with the old versions. Most of it is just name changes in the api. The only problem I had was that the function HCIVirtualTransportClass::read() only reads one byte at a time so I had to use the RTOS stream buffer that is exclusive to versions 2.0+. You can avoid this by putting all the functionality directly into HCI.cpp but that breaks compatibility with the other platforms. |
This would be so useful, especially now that Platformio supports 2.0... |
I would really like to see support for ESP32 |
@dominsch I tried BLE on esp32 and everything works great except changing MAC addresses. HCI.leSetRandomAddress() does nothing, i tried to debug what happened with HCI but it is way out of my ability, could you maybe look at it? |
Nice to hear that someone is using it. Can you provide a code snipped I can test? I looked in the documentation and leSetRandomAddress() is not listed. I don't think it's meant to be called by the user. |
I had tested this snippet and it didn't work, i am testing on a single core esp32 board so i had to compile the esp-idf for arduino IDE myself. #include <ArduinoBLE.h>
#include <utility/HCI.h>
uint8_t macaddress[] = {0xd2, 0x7b, 0x70, 0x1c, 0x0f, 0xd2};
void setup() {
Serial.begin(115200);
BLE.begin();
BLE.setLocalName("ESP");
BLE.advertise();
}
void loop() {
BLE.stopAdvertise();
macaddress[1]++;
HCI.leSetRandomAddress(macaddress);
BLE.advertise();
} |
You can call esp_base_mac_addr_set() before BLE.begin() to set a custom MAC address. The BLE mac address will be base address + 2. If you need to change it on the fly you will have to reinit the entire bluetooth stack which crashes at the moment and will take some time for me to fix. It looks like arduinoBLE doesn't currently doesn't allow the user to change the MAC address so you might want to open an issue and request the feature. |
Why close the PR though? |
The PR has been open for more than a year and there hasn't been any interest in merging it which is understandable since there are no official arduino boards that would benefit from this. I will try to make it stable enough so that it doesn't crash when calling BLE.end() and then open another PR. I think I might also just make a fork that removes some abstractions and doesn't depend on arduino at all so that it can be used standalone with the esp-IDF. I think its a shame this library isn't more popular despite using the lowest amount of resources among all the BLE stacks. |
@Nxtv2 This works now without crashing or leaking memory: #include <ArduinoBLE.h>
uint8_t macaddress[] = {0x00, 0x00, 0x70, 0x1c, 0x0f, 0x00};
void setup() {
}
void loop() {
esp_base_mac_addr_set(macaddress);
BLE.begin();
BLE.setLocalName("Mystery Device");
BLE.advertise();
delay(1000);
BLE.end();
macaddress[1]++;
} |
Added support for the esp32 chip using the virtual HCI. This has been tested on real hardware with "Arduino core for the ESP32" version 2.0.0.